package com.example.dmc_android_sellbreakfast_ver1;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class EditInforActivity extends Activity {
	private  EditText edt_name_edit,edt_numberRoom_edit;
	private TextView tv_edit_user;
	private Button btn_ok,btn_cancle;
	Database mDatabase;
	String account,pw;

	/* (non-Javadoc)
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_infor_edit_user);
		init();
		handle();
		ShowAllInfo();
	}

	private void init() {
		// TODO Auto-generated method stub
		tv_edit_user = (TextView)findViewById(R.id.tv_edit_user);
		edt_name_edit = (EditText)findViewById(R.id.edt_edit_name);
		edt_numberRoom_edit = (EditText)findViewById(R.id.edt_edit_numberRoom);
		btn_ok = (Button)findViewById(R.id.btn_ok_edit);
		btn_cancle = (Button)findViewById(R.id.btn_cancle_edit);
		mDatabase = new Database(this);
		Bundle mBundle = getIntent().getExtras();
		if(mBundle!=null)
		{
			account = mBundle.getString("account");
			pw = mBundle.getString("password");
		}
	}
	private void ShowAllInfo() {
		// TODO Auto-generated method stub
		mDatabase.open();
		String id = account;
		String name = mDatabase.getName(id,pw);
		 String account = mDatabase.getAccount(id, pw);
		 String numberRoom = mDatabase.getNumberRoom(id, pw);
		edt_name_edit.setText(name);
		edt_numberRoom_edit.setText(numberRoom);
		tv_edit_user.setText(account);
		mDatabase.close();
	}
	public void updateInfor()
	{
		String name = edt_name_edit.getText().toString();
		String numberRoom = edt_numberRoom_edit.getText().toString();
		if(true)
		{
			Toast.makeText(this, "Update thanh cong", 1000);
			ShowAllInfo();
		}
		else {
			Toast.makeText(this, "Update that bai", 1000);
		}
	}

	private void handle() {
		// TODO Auto-generated method stub
		btn_ok.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				updateInfor();
			}
		});
		btn_cancle.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
	}

}
